package customerEnter.Frame.redis.RedisModelDataStructure;

import java.util.ArrayList;
import java.util.List;

import customerEnter.Frame.redis.MemoryModel.RedisMemoryModel;

public class RedisModelData {

	private String		RedisModelName;
	private Class<?>	redisModelBean;

	public RedisModelData(String RedisModelName, Class<?> redisModelBean) {
		this.redisModelBean = redisModelBean;
		this.RedisModelName = RedisModelName;
	}
	
	//設置hash表的過期時間
	public void SetRedisExpire() throws Exception{
		new RedisMemoryModel(RedisModelName, redisModelBean).SetRedisExpire();
	}

	public void createModeldata() throws Exception {
		new RedisMemoryModel(RedisModelName, redisModelBean).createRedisModel();
	}

	public void deleteModelData(String id) throws Exception {
		new RedisMemoryModel(RedisModelName, redisModelBean).deleteRedisModelData(id);
	}

	public void addModelData(Object object) throws Exception {
		new RedisMemoryModel(RedisModelName, redisModelBean).addRedisModelValue(object);
	}
	
	public void updateModelData(Object object) throws Exception {
		new RedisMemoryModel(RedisModelName, redisModelBean).updateRedisModelvalue(object);
	}
	
	//更新緩存，更新某一條數據
	public <T> void updateOneModelData(String key,String id,T value) throws Exception{
		new RedisMemoryModel(RedisModelName, redisModelBean).updateRedisModelOneValue(key, id, value);
	}
	
	public <T> T queryModelData(String idFind) throws Exception {
		return new RedisMemoryModel(RedisModelName, redisModelBean).queryRedisModelVlaue(idFind);
	}

//  條件查詢
//	@SuppressWarnings("unchecked")
//	public <T> List<T> queryModelDataByCondition(String userid) throws Exception{
//		return (List<T>) new RedisMemoryModel(RedisModelName, redisModelBean).queryRedisModelByValue(userid);
//	}

	@SuppressWarnings("unchecked")
	public <T> List<T> queryModelListData(int size, int page) throws Exception {
		List<Object> list = new RedisMemoryModel(RedisModelName, redisModelBean).queryListRedisModel(size, page);
		List<Object> list2 = new ArrayList<Object>();
		for (Object object : list) {
			Object object2 = queryModelData(object.toString());
			list2.add(object2);
		}
		return (List<T>) list2;
	}

}
